package de.jmda.mview.fx.node.typeshape.relation;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Point2D;
import de.jmda.fx.node.ArrowOrthogonal;
import de.jmda.fx.node.ArrowOrthogonal.Orientation;
import de.jmda.mview.fx.node.typeshape.Typeshape;
import de.jmda.mview.fx.node.typeshape.Typeshape.Anchor;
import de.jmda.util.gui.awt.graphics.RelationEndpoint.Style;

public class RelationEndpointTargetIs
		extends RelationEndpointTarget
{
//	private final static Logger LOGGER =
//      Logger.getLogger(RelationEndpointTargetIs.class);

	/**
	 * target type shape, injected into constructor
	 */
	private Typeshape typeshape;

	public RelationEndpointTargetIs(Typeshape typeshape)
  {
	  super(typeshape);
		
		// store injected values
		this.typeshape = typeshape;
		
		// initially locate arrow at the bottom side of type's shape with up direction
		Anchor anchor = new Anchor();
		
		this.typeshape.addBottom(anchor);
		
		arrow =
				new ArrowOrthogonal(
						anchor.pointProperty().get(),
						10,
						Style.TRANSPARENT,
						false,
						4,
						Orientation.UP);

		anchor.pointProperty().addListener
		(
				new ChangeListener<Point2D>()
				{
					@Override
          public void changed(
          		ObservableValue<? extends Point2D> observable,
              Point2D oldValue, Point2D newValue)
          {
						arrow.setLayoutX(newValue.getX());
						arrow.setLayoutY(newValue.getY());

//						LOGGER.debug(arrow.coordinatesAsString());
          }
				}
		);
  }
}